#include <QDebug>
#include <QDir>
#include <QApplication>
#include <QWebFrame>

#include "mainwindow.h"

class HybridFWApplication : public QApplication
{
public:
    HybridFWApplication(int & argc, char ** argv ) : QApplication(argc, argv) {}
    void setWebFrame(QWebFrame *webFrame) { m_webFrame = webFrame; }

private:
    QWebFrame *m_webFrame;

};

/**
 * Takes three arguments:
 * Launcher.exe <identifier> <path> <panning enabled>
 * e.g. Launcher.exe 1234 widget\main.html true
 */
int main(int argc, char *argv[])
{
    HybridFWApplication a(argc, argv);

	if (argc == 4) {
        QFileInfo f(argv[2]);
        QString file = f.canonicalFilePath();

        if (QFile::exists(file)) {
			MainWindow w(argv[1], file, (QString(argv[3]) == "true"));
            a.setWebFrame(w.webFrame());
            w.showMaximized();
            return a.exec();
        }
    }

	QString args = "";
	for (int i=0;i<argc;i++) {
		args += "\n" + QString(argv[i]);
	}

    // Called if a valid file was not given
	MainWindow w(QString::number(argc) + "; " + args);
    w.show();

    return a.exec();
}
